package com.langsin.dao.impl;

import com.langsin.dao.UserDao;
import com.langsin.util.DataSourceUtil;
import com.langsin.vo.User;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDaoImpl implements UserDao{

    private Connection conn;
    private PreparedStatement ps;
    private ResultSet set;

    @Override
    public User queryUser(String username, String password) throws Exception {
        User user = null;
        conn = DataSourceUtil.getConnection();
        String sql = "select * from user where user_name = ? and user_pass = ?";
        ps = conn.prepareStatement(sql);
        ps.setString(1,username);
        ps.setString(2,password);
        set = ps.executeQuery();
        while(set.next()){
            user = new User();
            user.setUsername(username);
            user.setPassword(password);
            user.setCname(set.getString("cname"));
            user.setGender("男");
        }
        return user;
    }
}
